import request from '@/utils/request';
import { UserInfo } from '../system/user';
import moment from 'moment';

// 1. 获取标签
export function getExams(params = {}) {
  return request({
    url: '/exams',
    method: 'post',
    data: params
  });
}

export function addExams(params: any = {}) {
  const { userIDs, time, ...rest } = params;
  const startTime = moment(time[0]).valueOf()
  const endTime = moment(time[1]).valueOf()
  const data = {
    ...rest,
    userIDs: userIDs && userIDs.length > 0 ? JSON.stringify(userIDs) : null,
    startTime,
    endTime
  };
  return request({
    url: '/addExams',
    method: 'post',
    data
  });
}

export function deteleExams(params = {}) {
  return request({
    url: '/deteleExams',
    method: 'post',
    data: params
  });
}

export function updatExams(params = {}) {
  return request({
    url: '/updateExams',
    method: 'post',
    data: params
  });
}

export function uploadExams(params = {}) {
  return request({
    url: '/uploadExams',
    method: 'post',
    data: params
  });
}

export function getCommonUsers(params = {}) {
  return request<UserInfo[]>({
    url: '/api/user/common',
    method: 'post',
    data: params
  });
}
